
Ccay.Module.define("Ccay.example.ui.popup",function(page,$S){
	page.ready=function(){
		$("#popupDemo").ccayTab();		
	}
	// 清除已选择的数据
	page.reset=function(){
		$S("input[name=\"id1\"]").ccaySetValue("");
		$S("input[name=\"name1\"]").ccaySetValue("");
	}
	
	//打开单选弹出框
	page.popupRole = function() {
		var callback = function(role) {
			$S("input[name='id1']").val(role.id);
			$S("input[name='name1']").val(role.name);
		};
		var columns = [{
				header : $i18n("ccay.security.label.name"),
				id : 'name',
				isCondition : true
			}, {
				header : $i18n("ccay.common.label.description"),
				id : 'roleDesc',
				isCondition : true
			}];
		var rolePopupBean = {
			igrid : true,
			queryParam : {},
			servicePath : "services/manage/security/roleManage/list",
			uniqueKey : "id",
			//autoLoad:false,
			columns : columns,
			callback : callback,
			historyKey : "test_role_popup"
		};
		Ccay.Component.popup(rolePopupBean,
				$i18n("ccay.registry.label.popupTitle"), false);
	}
	
	//打开多选弹出框
	page.popupRoleMulti = function() {
		var callback = function(roles) {
			var roleids = "";
			rolenames = "";
			$.each(roles, function() {
						roleids += this.id + ",";
						rolenames += this.name + ",";
					});

			$("input[name='id2']").val(roleids);
			$("input[name='name2']").val(rolenames);
		};
		var selectedItems = $("input[name='id2']").val().split(",") || [];
		var columns = [{
				header : $i18n("ccay.security.label.name"),
				id : 'name',
				isCondition : true
			}, {
				header : $i18n("ccay.common.label.description"),
				id : 'roleDesc',
				isCondition : true
			}];
		var rolePopupBean = {
			igrid :true,
			queryParam : {},
			servicePath : "services/manage/security/roleManage/list",
			uniqueKey : "id",
			columns : columns,
			callback : callback,
			selectedItems : selectedItems
		};
		Ccay.Component.popup(rolePopupBean, 
				$i18n("ccay.registry.label.popupTitle"),
				selectedItems && true);
	};
	
	
	//--------------------- 添加 弹出框 去掉 历史记录的 demo 

	//打开多选弹出框
	page.popupRoleMulti1 = function() {
		var callback = function(roles) {
			var roleids = "";
			rolenames = "";
			$.each(roles, function() {
						roleids += this.id + ",";
						rolenames += this.name + ",";
					});

			$("input[name='id21']").val(roleids);
			$("input[name='name21']").val(rolenames);
		};
		var selectedItems = $("input[name='id21']").val().split(",") || [];
		var columns = [{
				header : $i18n("ccay.security.label.name"),
				id : 'name',
				isCondition : true
			}, {
				header : $i18n("ccay.common.label.description"),
				id : 'roleDesc',
				isCondition : true
			}];
		var rolePopupBean = {
			igrid :true,
			queryParam : {},
			historySupport : false,
			servicePath : "services/manage/security/roleManage/list",
			uniqueKey : "id",
			columns : columns,
			callback : callback,
			selectedItems : selectedItems
		};
		Ccay.Component.popup(rolePopupBean, 
				$i18n("ccay.registry.label.popupTitle"),
				selectedItems && true);
	};
	
	//--------------------- 添加 弹出框 去掉 历史记录的 demo 
	
	
	
	
	
	// 默认条件查询弹出框
	//bean.queryParam={name:$S("#defaultQueryParam").ccayGetValue()};
	page.popupRole2 = function() {
		var callback = function(role) {
			$S("input[name='id3']").val(role.id);
			$S("input[name='name3']").val(role.name);
		}
		var columns = [{
			header : $i18n("ccay.security.label.name"),
			id : 'name',
			isCondition : true
		}, {
			header : $i18n("ccay.common.label.description"),
			id : 'roleDesc',
			isCondition : true
		}];
		var bean = {
				igrid :true,
				queryParam : {},
				historySupport : false,
				servicePath : "services/manage/security/roleManage/list",
				uniqueKey : "id",
				columns : columns,
				callback : callback
		};
		bean.queryParam = {
			name : $S("#defaultQueryParam").ccayGetValue()
		};
		bean.allowEmptyCondition = false;
		
		Ccay.Component.popup(bean, $i18n("ccay.registry.label.popupTitle"));
	}
	// 默认条件查询弹出框2
	//bean.queryParam={name:$S("#defaultQueryParam").ccayGetValue()};
	page.popupRole21 = function() {
		var callback = function(role) {
			$S("input[name='id31']").val(role.id);
			$S("input[name='name31']").val(role.name);
		}
		var columns = [{
			header : $i18n("ccay.security.label.name"),
			id : 'name',
			isCondition : true
		}, {
			header : $i18n("ccay.common.label.description"),
			id : 'roleDesc',
			isCondition : true
		}];
		var bean = {
				igrid :true,
				queryParam : {},
				historySupport : false,
				servicePath : "services/manage/security/roleManage/list",
				uniqueKey : "id",
				columns : columns,
				callback : callback
		};
		bean.queryParam = function(){
			return {name : $S("#defaultQueryParam2").ccayGetValue()};
		};
		bean.allowEmptyCondition = false;
		
		Ccay.Component.popup(bean, $i18n("ccay.registry.label.popupTitle"));
	}    
	// 自定义条件区域
	page.popupByCondRender = function() {
		var callback = function(role) {
			$S("input[name='id4']").val(role.id);
			$S("input[name='name4']").val(role.name);
		};
		var columns = [
				  { header : $i18n("ccay.security.label.name"),
					id : 'name'}, 
				  { header : $i18n("ccay.common.label.description"),
					id : 'roleDesc'}];
		var rolePopupBean = {
			igrid : true,
			queryParam : {},
			servicePath : "services/manage/security/roleManage/list",
			uniqueKey : "id",
			columns : columns,
			callback : callback,
			condRender : function(){
				return "<ul class='ccay-horRow'><li class='ccay-horRow-item'>名称（自定义条件）：</li><li class='ccay-horRow-item'><input type='text' name='name' /></li></ul>"
			},
			initRender : function(divSelector){
				divSelector.find("input[name='status']").val("系统");
//				divSelector.find("input[name='status']").attr("service","FN:Ccay.example.ui.popup.getStatus").ccayCombobox({
//				    service:"FN:Ccay.example.ui.popup.getStatus",
//				    valueField:"id",
//				    displayField:"text"
//				})
			}
		};
		Ccay.Component.popup(rolePopupBean,
				$i18n("ccay.registry.label.popupTitle"), false);
	};
	
	page.getStatus = function(){
		return [{id:"1",text:"有效"},{id : "0", text:"无效"}];
	};
	
	// 单选自定义每页可选条数
	page.singlePopupCunstomPageSize = function(){
		var callback = function(role) {
			$S("input[name='ids']").val(role.id);
			$S("input[name='names']").val(role.name);
		};
		var columns = [{
				header : $i18n("ccay.security.label.name"),
				id : 'name',
				isCondition : true
			}, {
				header : $i18n("ccay.common.label.description"),
				id : 'roleDesc',
				isCondition : true
			}];
		var rolePopupBean = {
			igrid :true,
			pageSize:50,
			pageSizeList:[50,500],
			queryParam : {},
			servicePath : "services/manage/security/roleManage/list",
			uniqueKey : "id",
			columns : columns,
			callback : callback
		};
		Ccay.Component.popup(rolePopupBean,
				$i18n("ccay.registry.label.popupTitle"), false);
	};
	
	// 多选自定义每页可选条数
	page.multiPopupCunstomPageSize = function() {
		var callback = function(roles) {
			var roleidm = "";
			rolenamem = "";
			$.each(roles, function() {
						roleidm += this.id + ",";
						rolenamem += this.name + ",";
					});

			$("input[name='idm']").val(roleidm);
			$("input[name='namem']").val(rolenamem);
		};
		var selectedItems = $("input[name='idm']").val().split(",") || [];
		var columns = [{
				header : $i18n("ccay.security.label.name"),
				id : 'id',
				isCondition : true
			}, {
				header : $i18n("ccay.common.label.description"),
				id : 'description',
				isCondition : true
			}];
		var rolePopupBean = {
			igrid :true,
			pageSize:150,
			pageSizeList:[150,300],
			queryParam : {},
			servicePath : "services/manage/security/roleManage/list",
			uniqueKey : "id",
			columns : columns,
			callback : callback,
			selectedItems : selectedItems
		};
		Ccay.Component.popup(rolePopupBean, 
				$i18n("ccay.registry.label.popupTitle"),
				selectedItems && true);
	};
	
	
});


